package cn.hyy.hrm.service.impl;


import cn.hutool.crypto.SecureUtil;
import cn.hyy.basic.util.StrUtils;
import cn.hyy.hrm.controller.vo.RegisterVo;
import cn.hyy.hrm.domain.Sso;
import cn.hyy.hrm.domain.VipBase;
import cn.hyy.hrm.mapper.SsoMapper;
import cn.hyy.hrm.mapper.VipBaseMapper;
import cn.hyy.hrm.service.ISsoService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 会员登录账号 服务实现类
 * </p>
 *
 * @author solargen
 * @since 2020-04-12
 */
@Service
public class SsoServiceImpl extends ServiceImpl<SsoMapper, Sso> implements ISsoService {
    @Autowired
    private VipBaseMapper vipBaseMapper;

    /**
     * 用户注册
     * @param registerVo
     */
    @Override
    public void register(RegisterVo registerVo) {

        //sso添加数据返回主键
        Sso sso = new Sso();
        sso.setCreateTime(System.currentTimeMillis());
        sso.setPhone(registerVo.getPhoneNum());
        //随机盐值
        String salt = StrUtils.getComplexRandomString(6);
        sso.setSalt(salt);
        //密码加密
        String password = SecureUtil.md5(registerVo.getPassword() + salt);
        sso.setPassword(password);
        //初始化其他属性..........
        baseMapper.insert(sso);

        //关联表数据维护
        VipBase vipBase = new VipBase();
        vipBase.setSsoId(sso.getId());
        vipBase.setRegTime(System.currentTimeMillis());
        //其他属性填入初始值
        vipBaseMapper.insert(vipBase);

    }
}
